package com.jiawa.train.member.controller;

import com.jiawa.train.common.resp.PageResult;
import com.jiawa.train.common.resp.Result;
import com.jiawa.train.member.req.PassengerQueryReq;
import com.jiawa.train.member.req.PassengerSaveReq;
import com.jiawa.train.member.service.PassengerService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/passenger")
@Slf4j
public class PassengerController {

    @Resource
    private PassengerService passengerService;
    @PostMapping("/save")
    public Result save(@RequestBody @Valid PassengerSaveReq req) {
        passengerService.save(req);
        return Result.success();
    }
    @GetMapping("/page")
    public Result<PageResult> queryPassengerList(PassengerQueryReq  req) {
       PageResult pageResult = passengerService.queryPassengerList(req);
       return Result.success(pageResult);
    }
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Long id) {
        passengerService.delete(id);
        return Result.success();
    }

    @GetMapping("/queryPassengers")
    public Result<PageResult> queryPassenger() {
       PageResult passengerList = passengerService.queryPassengers();
       return Result.success(passengerList);
    }
}

